//
//  XDLMGestureViewController.m
//  xindailianmeng
//
//  Created by 许佳奇 on 17/2/8.
//  Copyright © 2017年 xindailianmeng.cn. All rights reserved.


//********绘制手势密码

#import "XDLMGestureViewController.h"
#import "GestureViewController.h"
#import "PCCircleViewConst.h"
#import "GestureVerifyViewController.h"
@interface XDLMGestureViewController ()

@property (nonatomic, weak) UISwitch *switchBtn;

@property (nonatomic, weak) UIButton *changeBtn;

@end

@implementation XDLMGestureViewController
{
    UIView *_backView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addViews];
   
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSUserDefaults *df = [NSUserDefaults standardUserDefaults];

    if ([df valueForKey:@"gestureFinalSaveKey"]) {
       self.switchBtn.on = YES;
        self.changeBtn.enabled = YES;
    } else {
        
        self.switchBtn.on = NO;
        self.changeBtn.enabled = NO;
    }
}

- (void)addViews
{
    self.title = @"手势密码";
    self.view.backgroundColor = kColorRGB(234, 234, 234);
    
    [self creatBtnWithFrame:CGRectMake(0, 10, kScreenW, 50) title:@"手势密码" image:nil tag:100];
    
    [self creatBtnWithFrame:CGRectMake(0, 70, kScreenW, 50) title:@"修改手势密码" image:@"nextInd" tag:101];
}

- (void)creatBtnWithFrame:(CGRect)frame title:(NSString *)title image:(NSString *)image tag:(NSInteger)tag {
    
    UIButton *btn = [[UIButton alloc] initWithFrame:frame];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"textfield-1"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"textfield-1"] forState:UIControlStateHighlighted];
    [btn setTitleColor:kColorRGB(102, 102, 102) forState:UIControlStateNormal];
    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    btn.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 15);
    [btn setBackgroundImage:[UIImage imageNamed:@"textfield-1"] forState:UIControlStateDisabled];
    if (tag == 100) {
        btn.enabled = YES;
        UISwitch *switchBtn = [[UISwitch alloc] initWithFrame:CGRectMake(kScreenW - 51 - 15, 9, 51, 50 - 18)];
        self.switchBtn = switchBtn;
        [switchBtn addTarget:self action:@selector(switchChang:) forControlEvents:UIControlEventValueChanged];
        [btn addSubview:switchBtn];
        
    } else {
        btn.enabled = YES;
        [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:image] forState:UIControlStateHighlighted];
         [btn setImage:[UIImage imageNamed:image] forState:UIControlStateDisabled];
        
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, - 6, 0, 0);
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, kScreenW - 30 - 6, 0, 0);
        [btn addTarget:self action:@selector(changeGesturePass) forControlEvents:UIControlEventTouchUpInside];
        self.changeBtn = btn;
    }
    btn.tag = tag;
    btn.titleLabel.font = kBaseFont_(14);
    [self.view addSubview:btn];
    
    
}
- (void)closeBtnClick
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
- (void)switchChang:(UISwitch *)switchBtn {
    
    if ([switchBtn isOn]) {
        NSLog(@"开");
        GestureViewController *gestureVc = [[GestureViewController alloc] init];
        gestureVc.type = GestureViewControllerTypeSetting;
        [self.navigationController pushViewController:gestureVc animated:YES];
        self.changeBtn.enabled = YES;
    }else {
        NSLog(@"关");
        self.changeBtn.enabled = NO;
        [PCCircleViewConst saveGesture:nil Key:@"gestureFinalSaveKey"];
    }
}

- (void)changeGesturePass {
    
    NSLog(@"-----");
//    [PCCircleViewConst saveGesture:nil Key:@"gestureFinalSaveKey"];
    GestureVerifyViewController *gestureVerifyVc = [[GestureVerifyViewController alloc] init];
    gestureVerifyVc.isToSetNewGesture = YES;
    [self.navigationController pushViewController:gestureVerifyVc animated:YES];
}
@end
